package com.colin.app.activity.method.blur;

import android.graphics.Bitmap;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;

import com.colin.app.R;
import com.colin.app.activity.method.MethodContract;
import com.colin.app.activity.method.MethodPresenterImpl;
import com.colin.app.app.AppActivity;
import com.colin.app.bean.DemoBean;
import com.colin.app.popupwindow.BlurPopupWindow;
import com.colin.library.help.ImageLoader;
import com.colin.library.other.Url;

/**
 * 高斯模糊效果
 */
public class BlurActivity extends AppActivity implements MethodContract.MethodView {
    private MethodContract.MethodPresenter mMethodPresenter = null;
    private ImageView image_blur_bg;
    private BlurPopupWindow mBlurPopupWindow = null;

    @Override
    protected void onDestroy() {

        mBlurPopupWindow = null;

        if (null != mMethodPresenter) {
            mMethodPresenter.destroy();
            mMethodPresenter = null;
        }
        super.onDestroy();
    }

    @Override
    public void initPresenter() {
        DemoBean demoBean = getIntent().getExtras().getParcelable("clazz");
        mMethodPresenter = new MethodPresenterImpl(this, this, demoBean);
    }

    @Override
    public int initViewLayoutID() {
        return R.layout.activity_blur;
    }

    @Override
    public void initView() {
        this.image_blur_bg = (ImageView) this.findViewById(R.id.image_blur_bg);
    }

    @Override
    public void initData() {
        mMethodPresenter.setData();
        ImageLoader.getInstance().loadImageByGlide(image_blur_bg, Url.image_url[0]);
    }

    @Override
    public void initListener() {
        image_blur_bg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPop();
            }
        });
    }

    private void showPop() {
        if (mBlurPopupWindow == null) {
            mBlurPopupWindow = new BlurPopupWindow(this, captureScreenWindow());
        }
        mBlurPopupWindow.showAtLocation(activity_view, Gravity.CENTER, 0, 0);
    }

    /**
     * 截取全屏
     *
     * @return
     */
    public Bitmap captureScreenWindow() {
        getWindow().getDecorView().setDrawingCacheEnabled(true);
        return getWindow().getDecorView().getDrawingCache();
    }
}
